package 行为型模式.策略;

/**
 * @ClassNameCategoryTest
 * @Description 策略模式，以做鱼为例，
 * @Author
 * @Date2022/1/4 17:16
 **/
public class CategoryTest {
    public static void main(String[] args) {
        Fish hotFish = new HotFish();
        Fish redCookedFish = new RedCookedFish();

        // 做水煮鱼
        CookContext cookContext = new CookContext();
        cookContext.setFish(hotFish);
        cookContext.cooke();
        System.out.println("----------------------------");
        // 做红烧鱼
        cookContext.setFish(redCookedFish);
        cookContext.cooke();


    }
}

interface Fish{
    void cook();
}
class HotFish implements Fish{

    @Override
    public void cook() {
        System.out.println("做水煮鱼");
    }
}
class RedCookedFish implements Fish{

    @Override
    public void cook() {
        System.out.println("做红烧鱼鱼");
    }
}
class CookContext {
    private Fish fish;

    public Fish getFish() {
        return fish;
    }

    public void setFish(Fish fish) {
        this.fish = fish;
    }

    void cooke(){
        this.fish.cook();
    }
}
